package com.qianduo.front.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodeFilter implements Filter {
	private String encoding;
	
	public void destroy() {
	}

	public void doFilter(ServletRequest sreq, ServletResponse sres, FilterChain fc) throws IOException, ServletException {
		if(null != encoding && !"".equals(encoding)){
			sreq.setCharacterEncoding(encoding);
			sres.setCharacterEncoding(encoding);
		}
		fc.doFilter(sreq, sres);
	}

	public void init(FilterConfig fc) throws ServletException {
		String ec		= fc.getInitParameter("encoding");
		encoding		= ec;
	}
}
